package game;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.geom.Point2D;

abstract class GameObject {
	
	private Image image;
	private Point2D position;
	private Point2D size;
	private Point2D sourcePosition;
	private Point2D sourceSize;
	
	public GameObject(String image, Point2D position, Point2D size, Point2D sourcePosition, Point2D sourceSize)
	{
		if (image != null)
			this.image = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource(image));
		this.position = position;
		this.size = size;
		this.sourcePosition = sourcePosition;
		this.sourceSize = sourceSize;
	}
	
	//Begin Get & Set
	public Image getImage() {
		return image;
	}
	public void setImage(Image image) {
		this.image = image;
	}
	public Point2D getPosition() {
		return position;
	}
	public void addPosition(Point2D addPos)
	{
		position = new Point2D.Double(position.getX() + addPos.getX(), position.getY() + addPos.getY());
	}
	public void setPosition(Point2D position) {
		this.position = position;
	}
	public Point2D getSize() {
		return size;
	}
	public void setSize(Point2D size) {
		this.size = size;
	}
	public Point2D getSourcePosition() {
		return sourcePosition;
	}
	public void setSourcePosition(Point2D sourcePosition) {
		this.sourcePosition = sourcePosition;
	}
	public Point2D getSourceSize() {
		return sourceSize;
	}
	public void setSourceSize(Point2D sourceSize) {
		this.sourceSize = sourceSize;
	}
	//End Get & Set

	public void update()
	{
	}
	
	public void draw(Graphics2D g2d)
	{
		if (sourcePosition == null && sourceSize == null)
			g2d.drawImage(image, (int)this.position.getX(), (int)this.position.getY(), (int)this.size.getX(), (int)this.size.getY(), null);
		else
			g2d.drawImage(image, (int)this.position.getX(), (int)this.position.getY(), 
								 (int)this.position.getX() + (int)this.size.getX(), (int)this.position.getY() + (int)this.size.getY(),
					 			 (int)this.sourcePosition.getX(), (int)this.sourcePosition.getY(), 
					 			 (int)this.sourcePosition.getX() + (int)this.sourceSize.getX(), (int)this.sourcePosition.getY() + (int)this.sourceSize.getY(), null);
	}

}
